<template>
  <PageWrapper dense>
    <BasicTable @register="register">
      <template #toolbar>
        <a-button type="primary" @click="handleNew">新增</a-button>
        <TableAction />
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '编辑',
              onClick: handleEdit.bind(null, record),
            },
            {
              label: '删除',
              color: 'error',
              popConfirm: {
                title: '是否确认删除',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
  </PageWrapper>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { getBasicColumns, getFormConfig } from './domainListData';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useGo } from '/@/hooks/web/usePage';
  import { PageWrapper } from '/@/components/Page';
  import { deleTeDomain, getAllDomain } from '/@/api/ccb/ccbList';

  export default defineComponent({
    name: 'DomainList',
    components: { BasicTable, TableAction, PageWrapper },
    setup() {
      const go = useGo();
      const { createMessage } = useMessage();
      const [register, { reload }] = useTable({
        title: '域名列表',
        api: getAllDomain,
        columns: getBasicColumns(),
        // pagination: { pageSize: 10 },
        useSearchForm: true,
        formConfig: getFormConfig(),
        striped: false,
        showIndexColumn: false,
        canResize: false,
        bordered: true,
        actionColumn: {
          width: 80,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: undefined,
        },
        rowKey: 'activityNo',
      });
      async function handleDelete(record: Recordable) {
        await deleTeDomain({ activityNo: record.activityNo });
        createMessage.success('删除成功');
        reload();
      }
      function handleNew() {
        go('/ccb/editDomain');
      }
      function handleEdit(record: Recordable) {
        go('/ccb/editDomain?activityNo=' + record.activityNo);
      }
      return {
        register,
        handleDelete,
        handleNew,
        handleEdit,
        getAllDomain,
      };
    },
  });
</script>
